<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="../../../../lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.useso.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="../../../../lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="../../../../css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="../../../../images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="../../../../images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="../../../../images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="../../../../images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="我们在安装好操作系统后一般都需要对系统做一些针对于自己环境的情况做一下系统初始化，这个我们一般用shell脚本来跑一遍，把相关的参数、配置调整一下就好了。使用下面这个脚本就可以初始化我们系统啦。 #!/bin/bash #Version 1.9 #Auth: guomaoqiu #For CentOS_mini #Made on 2015-06-19 echo “   “echo “#######">
<meta name="keywords" content="devops,Linux,Kubernetes,Flask,Python,Shell">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux系统初始化脚本">
<meta property="og:url" content="http://demo_demo.gitee.io/2015/06/19/linux-e7-b3-bb-e7-bb-9f-e5-88-9d-e5-a7-8b-e5-8c-96/index.html">
<meta property="og:site_name" content="运维人">
<meta property="og:description" content="我们在安装好操作系统后一般都需要对系统做一些针对于自己环境的情况做一下系统初始化，这个我们一般用shell脚本来跑一遍，把相关的参数、配置调整一下就好了。使用下面这个脚本就可以初始化我们系统啦。 #!/bin/bash #Version 1.9 #Auth: guomaoqiu #For CentOS_mini #Made on 2015-06-19 echo “   “echo “#######">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-12-10T06:42:10.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux系统初始化脚本">
<meta name="twitter:description" content="我们在安装好操作系统后一般都需要对系统做一些针对于自己环境的情况做一下系统初始化，这个我们一般用shell脚本来跑一遍，把相关的参数、配置调整一下就好了。使用下面这个脚本就可以初始化我们系统啦。 #!/bin/bash #Version 1.9 #Auth: guomaoqiu #For CentOS_mini #Made on 2015-06-19 echo “   “echo “#######">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://demo_demo.gitee.io/2015/06/19/linux-e7-b3-bb-e7-bb-9f-e5-88-9d-e5-a7-8b-e5-8c-96/">





  <title>Linux系统初始化脚本 | 运维人</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/guomaoqiu" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#FD6C6C; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">运维人</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">生命在于折腾</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://demo_demo.gitee.io">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OutMan">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="运维人">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux系统初始化脚本</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-06-19T20:06:31+08:00">
                2015-06-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="../../../../categories/Shell/" itemprop="url" rel="index">
                    <span itemprop="name">Shell</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>我们在安装好操作系统后一般都需要对系统做一些针对于自己环境的情况做一下系统初始化，这个我们一般用shell脚本来跑一遍，把相关的参数、配置调整一下就好了。使用下面这个脚本就可以初始化我们系统啦。</p>
<p>#!/bin/bash</p>
<p>#Version 1.9</p>
<p>#Auth: guomaoqiu</p>
<p>#For CentOS_mini</p>
<p>#Made on 2015-06-19</p>
<p>echo “   “<br>echo “#############################################################################”<br>echo “#  Initialize for the CentOS 6.4/6.5 mini_installed.                        #”<br>echo “#                                                                           #”<br>echo “#  Please affirm this OS connected net already before running this script ! #”<br>echo “#                                                                           #”<br>echo “#  must first connect to the Internet. because yum need it.                  #”<br>echo “#############################################################################”<br>echo “   “</p>
<p>format() {</p>
<pre><code> #echo -e &quot;\\033\[42;37m ########### Finished ########### \\033\[0m&quot;        
 sleep 5
 echo -e &quot;\\033\[42;37m ########### Finished ########### \\033\[0m&quot; 
 echo &quot;  &quot;
}
</code></pre><p>##########################################################################<br># Set time 时区/时间同步设置<br>echo “Set time.”<br>/bin/cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &amp;&gt; /dev/null<br>yum -y install ntpdate &amp;&gt; /dev/null<br>ntpdate  0.centos.pool.ntp.org &amp;&gt; /dev/null<br>hwclock -w<br>format</p>
<p>####################################################################################</p>
<p>#Set network 网卡开机自启动</p>
<p>#sed -i “s/ONBOOT=no/ONBOOT=yes/g”  /etc/sysconfig/network-scripts/ifcfg-eth0</p>
<p>#sed -i “s/NM_CONTROLLED=no/NM_CONTROLLED=no/g”/etc/sysconfig/network-scripts/ifcfg-eth0</p>
<p>#/etc/init.d/network restart &amp;&gt;/dev/null</p>
<p>#echo “==================================” &gt;&gt; $LOG</p>
<p>#format</p>
<p>##########################################################################<br># Create Log 创建该脚本运行记录日志<br>echo “Create log file.”<br>DATE1=`date +”%F %H:%M”`<br>LOG=/var/log/sysinitinfo.log<br>echo $DATE1 &gt;&gt; $LOG<br>echo “——————————————“ &gt;&gt; $LOG<br>echo “For CentOS_mini” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>echo “Set timezone is Shanghai” &gt;&gt; $LOG<br>echo “Finished ntpdate” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Disabled Selinux 禁用Selinux<br>echo “Disabled SELinux.”<br>sed -i ‘s/^SELINUX=enforcing/SELINUX=disabled/‘ /etc/sysconfig/selinux<br>echo “==================================================”<br>echo “Disabled SELinux.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Stop iptables 禁用iptables<br>echo “Stop iptables.”<br>service iptables stop &amp;&gt; /dev/null<br>chkconfig –level 35 iptables off<br>echo “Stop iptables.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Disable ipv6 禁用IPV6<br>echo “Disable ipv6.”<br>echo “alias net-pf-10 off” &gt;&gt; /etc/modprobe.conf<br>echo “alias ipv6 off” &gt;&gt; /etc/modprobe.conf<br>chkconfig –level 35 ip6tables off<br>echo “Disable ipv6.”&gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>##########################################################################</p>
<p>#Set history commands  设置命令历史记录参数<br>echo “Set history commands.”<br>echo “HISTFILESIZE=4000” &gt;&gt; /etc/bashrc<br>echo “HISTSIZE=4000” &gt;&gt; /etc/bashrc<br>echo “HISTTIMEFORMAT=’%F/%T’” &gt;&gt; /etc/bashrc<br>source /etc/bashrc<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>##########################################################################<br># Epel 升级epel源<br>echo “Install epel”<br>rpm -Uvh <a href="http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm" target="_blank" rel="noopener">http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm</a> &amp;&gt; /dev/null<br>sed -i “s/^#base/base/g” /etc/yum.repos.d/epel.repo<br>sed -i “s/^mirr/#mirr/g” /etc/yum.repos.d/epel.repo<br>echo “==================================================”<br>echo “Install epel” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>##########################################################################</p>
<p>#Yum install Development tools  安装开发包组及必备软件<br>echo “Install Development tools(It will be a moment,wait……)”<br>yum groupinstall -y “Development tools” &amp;&gt; /dev/null<br>yum groupinstall -y “Server Platform Development” &amp;&gt; /dev/null<br>yum groupinstall -y “Desktop Platform Development” &amp;&gt; /dev/null<br>yum groupinstall -y “chinese-support” &amp;&gt;/dev/null<br>for I in bind-utils lrzsz wget gcc gcc-c++ vim htop ;do<br>    yum install -y $I<br>done<br>echo “==================================================”<br>echo “Install Development tools” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>##########################################################################<br># Yum update bash and openssl  升级bash/openssl<br>echo “Update bash and openssl”<br>yum -y update bash &amp;&gt; /dev/null<br>yum -y update openssl &amp;&gt; /dev/null<br>echo “==================================================”<br>echo “Update bash and openssl” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Set ssh 设置ssh登录策略<br>echo “Disabled EmptyPassword.”<br>echo “Disabled SSH-DNS.”<br>echo “Set timeout is 6m.”<br>sed -i “s/^#PermitEmptyPasswords/PermitEmptyPasswords/“ /etc/ssh/sshd_config<br>sed -i “s/^#LoginGraceTime 2m/LoginGraceTime 6m/“ /etc/ssh/sshd_config<br>echo “UseDNS no” &gt;&gt; /etc/ssh/sshd_config<br>echo “==================================================”<br>echo “Disabled EmptyPassword.” &gt;&gt; $LOG<br>echo “Disabled SSH-DNS.” &gt;&gt; $LOG<br>echo “Set timeout is 6m.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Set default init 3  设置系统默认初始化<br>echo “Default init 3.”<br>sed -i ‘s/^id:5:initdefault:/id:3:initdefault:/‘ /etc/inittab<br>echo “==================================================”<br>echo “Default init 3.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Stop Service  关闭不必要的服务<br>echo “Some services are turned off now.”<br>for SER in rpcbind postfix portreserve certmonger mdmonitor blk-availability lvm2-monitor udev-post cups dhcpd firstboot gpm haldaemon hidd ip6tables ipsec isdn kudzu lpd mcstrans messagebus microcode_ctl netfs nfs nfslock nscd acpid anacron apmd atd auditd autofs avahi-daemon avahi-dnsconfd bluetooth cpuspeed pcscd portmap readahead_early restorecond rpcgssd rpcidmapd rstatd sendmail setroubleshoot snmpd sysstat xfs xinetd yppasswdd ypserv yum-updatesd<br> do<br>    /sbin/chkconfig –list $SER &amp;&gt; /dev/null<br>  if [ $? -eq 0 ]<br>    then<br>      chkconfig –level 35  $SER off<br>    echo “$SER” &gt;&gt; $LOG<br>  fi<br> done<br>echo “==================================================”<br>echo “Some services are turned off now:” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Del unnecessary users 删除不必要的用户<br>echo “Del unnecessary users.”<br>for USERS in adm lp sync shutdown halt mail news uucp operator games gopher<br> do<br>  grep $USERS /etc/passwd &amp;&gt;/dev/null<br>  if [ $? -eq 0 ]<br>   then<br>    userdel $USERS &amp;&gt; /dev/null<br>    echo $USERS &gt;&gt; $LOG<br>  fi<br> done<br>echo “==================================================”<br>echo “Del unnecessary users.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Del unnecessary groups 删除不必要的用户组<br>echo “Del unnecessary groups.”<br>for GRP in adm lp mail news uucp games gopher mailnull floppy dip pppusers popusers slipusers daemon<br> do<br>  grep $GRP /etc/group &amp;&gt; /dev/null<br>  if [ $? -eq 0 ]<br>   then<br>    groupdel $GRP &amp;&gt; /dev/null<br>    echo $GRP &gt;&gt; $LOG<br>  fi<br> done<br>echo “==================================================”<br>echo “Del unnecessary groups.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Disabled reboot by keys ctlaltdelete 禁用ctlaltdelete重启功能<br>echo “Disabled reboot by keys ctlaltdelete”<br>sed -i ‘s/^exec/#exec/‘ /etc/init/control-alt-delete.conf<br>echo “==================================================”<br>echo “Disabled reboot by keys ctlaltdelete” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Set ulimit  设置文件句柄数<br>echo “Set ulimit 1000000”<br>echo “<em>    soft    nofile  1000000” &gt;&gt; /etc/security/limits.conf<br>echo “</em>    hard    nofile  1000000” &gt;&gt; /etc/security/limits.conf<br>echo “<em>    soft    nproc 102400” &gt;&gt; /etc/security/limits.conf<br>echo “</em>    hard    nproc 102400” &gt;&gt; /etc/security/limits.conf<br>sed -i ‘s/102400/1000000/‘ /etc/security/limits.d/90-nproc.conf<br>echo “==================================================”<br>echo “Set ulimit 1000000” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Set login message 设置登录时显示的信息<br>echo “Set login message.”<br>echo “This is not a public Server” &gt; /etc/issue<br>echo “This is not a public Server” &gt; /etc/redhat-release<br>echo “==================================================”<br>echo “Set login message.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Record SUID and SGID files<br>DATE2=`date +”%F”`<br>echo “Record SUID and SGID files.”<br>echo “SUID — “ &gt; /var/log/SuSg_”$DATE2”.log<br>find / -path ‘/proc’  -prune -o -perm -4000 &gt;&gt; /var/log/SuSg_”$DATE2”.log<br>echo “—————————————————— “ &gt;&gt; /var/log/SuSg_”$DATE2”.log<br>echo “SGID — “ &gt;&gt; /var/log/SuSg_”$DATE2”.log<br>find / -path ‘/proc’  -prune -o -perm -2000 &gt;&gt; /var/log/SuSg_”$DATE2”.log<br>echo “==================================================”<br>echo “Record SUID and SGID.” &gt;&gt; $LOG<br>echo “Record is in /var/log/SuSg_”$DATE2”.log” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Disabled crontab send mail 禁用执行任务计划时向root发送邮件<br>echo “Disable crontab send mail.”<br>sed -i ‘s/^MAILTO=root/MAILTO=””/‘ /etc/crontab<br>sed -i ‘s/^mail\.\*/mail\.err/‘ /etc/rsyslog.conf<br>echo “==================================================”<br>echo “Disable crontab send mail.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Set ntp client 设置时间服务客户端<br>echo “Set ntp client.”<br>SED() {<br>    cp -p /etc/ntp.conf /etc/ntp.conf.bak<br>    sed -i ‘/^server/d’ /etc/ntp.conf<br>    sed -i ‘/^includefile/ i\server 0.centos.pool.ntp.org iburst’ /etc/ntp.conf<br>    sed -i ‘/0.centos.pool.ntp.org/ a\server 1.centos.pool.ntp.org iburst’ /etc/ntp.conf<br>    sed -i ‘/1.centos.pool.ntp.org/ a\server 2.centos.pool.ntp.org iburst’ /etc/ntp.conf<br>    sed -i ‘/2.centos.pool.ntp.org/ a\server 3.centos.pool.ntp.org iburst’ /etc/ntp.conf<br>    chkconfig –level 35 ntpd on &amp;&gt; /dev/null<br>    echo “==================================================”<br>}<br>rpm -q ntp &amp;&gt; /dev/null<br>if [ $? -eq 0 ]<br>  then<br>    SED<br>  else<br>   yum -y install ntp &amp;&gt; /dev/null<br>   SED<br>fi<br>echo “Set ntp client.” &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Set sysctl.conf 设置内核参数<br>echo “Set sysctl.conf”</p>
<p>#web应用中listen函数的backlog默认会将内核参数的net.core.somaxconn限制到128，而nginx定义的NGX_LISTEN_BACKLOG默认是511，所以必须调整,一般调整为2048<br>echo “net.core.somaxconn = 2048” &gt;&gt; /etc/sysctl.conf</p>
<p>echo “net.core.rmem_default = 262144” &gt;&gt; /etc/sysctl.conf<br>echo “net.core.wmem_default = 262144” &gt;&gt; /etc/sysctl.conf<br>echo “net.core.rmem_max = 16777216” &gt;&gt; /etc/sysctl.conf<br>echo “net.core.wmem_max = 16777216” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_rmem = 4096 4096 16777216” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_wmem = 4096 4096 16777216” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_mem = 786432 2097152 3145728” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_max_syn_backlog = 16384” &gt;&gt; /etc/sysctl.conf<br>echo “net.core.netdev_max_backlog = 20000” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_fin_timeout = 15” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_tw_reuse = 1” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_tw_recycle = 1” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.tcp_max_orphans = 131072” &gt;&gt; /etc/sysctl.conf<br>echo “net.ipv4.ip_local_port_range = 1024 65535” &gt;&gt; /etc/sysctl.conf<br>echo “Set sysctl.conf —- “ &gt;&gt; $LOG<br>/sbin/sysctl  -p &gt;&gt; $LOG<br>echo “==================================” &gt;&gt; $LOG<br>format</p>
<p>###########################################################################<br># Done<br>echo “Finished,You can check infomations in $LOG .”</p>
<p>#echo “System will reboot in 60s.”</p>
<p>#shutdown -r 1</p>
<p>如果有不对的地方，各位大婶可以提出来，大家一起进步哈；谢谢您的意见。 Download Script: <a href="http://www.sctux.com/project/initsystem.sh" target="_blank" rel="noopener">initsystem.sh</a></p>

      
    </div>
    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>


  
</div>
    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="../../../04/23/e9-80-9a-e8-bf-87-ulimit-e6-94-b9-e5-96-84-e7-b3-bb-e7-bb-9f-e6-80-a7-e8-83-bd/" rel="next" title="通过 Ulimit 改善系统性能">
                <i class="fa fa-chevron-left"></i> 通过 Ulimit 改善系统性能
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="../../../08/12/e5-ad-a6-e4-b9-a0saltstack-e5-b0-8f-e8-ae-b0-e7-ac-ac-e4-b8-80-e7-ab-a0-e3-80-8a-e5-ae-89-e8-a3-85-e5-8f-8a-e7-ae-80-e5-8d-95-e6-b5-8b-e8-af-95-e3-80-8b/" rel="prev" title="学习SaltStack小记---第一章《安装及简单测试》">
                学习SaltStack小记---第一章《安装及简单测试》 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="https://raw.githubusercontent.com/guomaoqiu/myblog_backup/master/uploads/myphoto.png" alt="OutMan">
            
              <p class="site-author-name" itemprop="name">OutMan</p>
              <p class="site-description motion-element" itemprop="description">😊</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="../../../../archives/">
              
                  <span class="site-state-item-count">79</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="../../../../categories/index.html">
                  <span class="site-state-item-count">22</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="../../../../tags/index.html">
                  <span class="site-state-item-count">46</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/guomaoqiu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i></a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:guomaoqiu@google.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i></a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OutMan</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="../../../../lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="../../../../lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="../../../../js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="../../../../js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="../../../../js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="../../../../js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="../../../../js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="../../../../js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
